package com.binary.markdownrecord.util;

import lombok.Data;
import org.springframework.data.domain.Sort;

import java.util.List;
import java.util.Map;

@Data
public class PageAndOrder {
    private final static String DESC = "desc";
    private Integer pageSize;
    private Integer page;
    private List<Map<String, String>> orderMapList;


    public Sort.Order[] offerSortOrder() {
        List<Map<String, String>> orderList = orderMapList;
        Sort.Order[] orders = new Sort.Order[orderList.size()];
        for (int i = 0; i < orderList.size(); i++) {
            Map<String, String> orderMap = orderList.get(i);
            String name = orderMap.get("name");
            orders[i] = DESC.equals(orderMap.get("order")) ? Sort.Order.desc(name) : Sort.Order.asc(name);
        }
        return orders;
    }
}
